<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:gml="http://www.opengis.net/gml" 
	xmlns:ogr="http://ogr.maptools.org/"
	xmlns:ramon_geo="http://ec.europa.eu/eurostat/ramon/ontologies/geographic.rdf#" 
	xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<xsl:output method="xml" omit-xml-declaration="yes" doctype-system="http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd" doctype-public="-//W3C//DTD XHTML+RDFa 1.0//EN" indent="yes"/>
	
<xsl:template match="/ogr:FeatureCollection">
	
	<xsl:variable name="nuts_dump" select="document('../sources/ramon/nuts2008.rdf')"/>
	
	<xsl:result-document href="id/index.php">

		<html> 	
		<head> 
		  <title property="dc:title">Index of NUTS levels</title> 
		  <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
		  <link rel="stylesheet" type="text/css" href="../css/style.css"/> 
		</head> 

		<body> 


		    <div id="container">
		      <xsl:processing-instruction name="php">
			  include('../header.php');
		      </xsl:processing-instruction>
		      <div id="content">
			<h1>Index of NUTS levels</h1>
			
			<p>The NUTS-region are based on the existing national administrative subdivisions. In countries where only one or two regional subdivisions 
			exist, or where the size of existing subdivisions is too small, a second and/or third level is created. This may be on the first level 
			(ex. France, Italy, Greece, and Spain), on the second (ex. Germany) and/or third level (ex. Belgium).[12] In smaller countries, where the entire
			country would be placed on the NUTS 2 or even NUTS 3 level (ex. Luxembourg, Cyprus, Ireland), levels 1, 2 and/or 3 are identical to the level
			above and/or to the entire country.</p>
			
			<p>The thresholds in the table below are used as guidelines for establishing the regions, but they are not applied rigidly.</p>
			
			<table>
			<tr>
				<th>Level</th>
				<th>Description</th>
				<th>Minimum</th>
				<th>Maximum</th>
			</tr>
			<tr>
				<td><a href="nuts0.html">NUTS 0</a></td>
				<td>Countries</td>
				<td></td>
				<td></td>
			</tr>
			<tr>
				<td><a href="nuts1.html">NUTS 1</a></td>
				<td>States</td>
				<td>3 million</td>
				<td>7 million</td>
			</tr>
			<tr>
				<td><a href="nuts2.html">NUTS 2</a></td>
				<td>Administrative regions within states</td>
				<td>800.000	</td>
				<td>3 million</td>
			</tr>
			<tr>
				<td><a href="nuts3.html">NUTS 3</a></td>
				<td>Counties/districts and greater metropolitan areas</td>
				<td>150.000</td>
				<td>800.000</td>
			</tr>
			</table>
		      </div>
		    </div>
		<xsl:processing-instruction name="php">
		  include('../footer.php');
		</xsl:processing-instruction>
		</body> 
		</html> 

	</xsl:result-document>
	
	<xsl:result-document href="id/nuts0.php">
		<xsl:call-template name="nuts_index">
			<xsl:with-param name="level" select="0"/>
			<xsl:with-param name="nuts_dump" select="$nuts_dump"/>
		</xsl:call-template>
	</xsl:result-document>
	
	<xsl:result-document href="id/nuts1.php">
		<xsl:call-template name="nuts_index">
			<xsl:with-param name="level" select="1"/>
			<xsl:with-param name="nuts_dump" select="$nuts_dump"/>
		</xsl:call-template>
	</xsl:result-document>
	
	<xsl:result-document href="id/nuts2.php">
		<xsl:call-template name="nuts_index">
			<xsl:with-param name="level" select="2"/>
			<xsl:with-param name="nuts_dump" select="$nuts_dump"/>
		</xsl:call-template>
	</xsl:result-document>
	
	<xsl:result-document href="id/nuts3.php">
		<xsl:call-template name="nuts_index">
			<xsl:with-param name="level" select="3"/>
			<xsl:with-param name="nuts_dump" select="$nuts_dump"/>
		</xsl:call-template>
	</xsl:result-document>
	
</xsl:template>

<xsl:template name="nuts_index">
	<xsl:param name="level" />
	<xsl:param name="nuts_dump" />
<!--
		<xsl:processing-instruction name="php">
		    echo '<?xml version="1.0" encoding="utf-8"?>';
		    echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">';
		</xsl:processing-instruction> -->
		<html> 	
		<head> 
		  <title property="dc:title">Index of NUTS level <xsl:value-of select="$level" /> regions</title> 
		  <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
		  <link rel="stylesheet" type="text/css" href="../css/style.css"/> 
		</head> 

		<body> 
		    <div id="container">
		      <xsl:processing-instruction name="php">
			include('../header.php');
		      </xsl:processing-instruction>
		      <div id="content">
			  <h1>Index of NUTS level <xsl:value-of select="$level" /> regions</h1>
			  
			  <table>
			  <tr>
				  <th style="width:40%;">Region</th>
				  <th>HTML</th>
				  <th>Turtle</th>
				  <th>RDF/XML</th>
				  <th>GML</th>
				  <th>KML</th>
			  </tr>
			  <xsl:for-each select='gml:featureMember/ogr:NUTS_RG_60M_2006[ogr:STAT_LEVL_=$level]' >
				  <xsl:variable name="nuts_id" select="ogr:NUTS_ID"/>
				  <xsl:apply-templates select="ogr:geometryProperty">
					  <xsl:with-param name="nuts_node" select="$nuts_dump/rdf:RDF/ramon_geo:NUTSRegion[@rdf:about=$nuts_id]" />
					  <xsl:with-param name="nuts_id" select="$nuts_id" />
				  </xsl:apply-templates>
			  </xsl:for-each>
			  </table>
		      </div>
		    </div> 
		    <xsl:processing-instruction name="php">
		      include('../footer.php');
		    </xsl:processing-instruction>
		</body> 
		</html> 

</xsl:template>

<xsl:template name="geometry" match="ogr:geometryProperty">
	<xsl:param name="nuts_node" />
	<xsl:param name="nuts_id" />

	<tr>
		<td><a href="{concat('http://nuts.geovocab.org/id/',$nuts_id)}"><xsl:value-of select="$nuts_node/rdfs:label" /></a></td>
		<td><a href="{concat('http://nuts.geovocab.org/id/',$nuts_id,'.html')}">Feature/Geometry</a></td>
		<td><a href="{concat('http://nuts.geovocab.org/id/',$nuts_id,'.ttl')}">Feature</a> | <a href="{concat('http://nuts.geovocab.org/id/',$nuts_id,'_geometry.ttl')}">Geometry</a></td>
		<td><a href="{concat('http://nuts.geovocab.org/id/',$nuts_id,'.rdf')}">Feature</a> | <a href="{concat('http://nuts.geovocab.org/id/',$nuts_id,'_geometry.rdf')}">Geometry</a></td>
		<td><a href="{concat('http://nuts.geovocab.org/id/',$nuts_id,'_geometry.gml')}">Geometry</a></td>
		<td><a href="{concat('http://nuts.geovocab.org/id/',$nuts_id,'_geometry.kml')}">Geometry</a></td>
	</tr>
</xsl:template>

</xsl:stylesheet>